package com.hmy.pig.controller;


import com.hmy.pig.domain.HmyPigPregnancy;
import com.hmy.pig.service.PigPregnancyService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhl
 * @descript 描述
 * @date 2024/2/1 12:44
 */
@RestController
@RequestMapping("/pigPregnancy")
public class HmypigPregnancyController extends BaseController {
    @Autowired
    private PigPregnancyService pigPregnancyService;

    /**
     * 根据条件分页查询猪只分娩记录列表:  条件 母猪耳号、妊检类型、妊检负责人、妊检时间
     *
     * @param pigCode 猪只耳号
     * @param pregnancyTestType 妊检方式
     * @param pregnancyTestManager 妊检负责人
     * @param dateStart 妊检 开始时间
     * @param dateEnd 妊检结束时间
     * @return 猪只信息集合信息
     */
    @RequiresPermissions("hmy:pigPregnancy:list")
    @GetMapping("/list")
    public TableDataInfo list(String pigCode ,
                              Integer pregnancyTestType,
                              String pregnancyTestManager,
                              String dateStart,
                              String dateEnd)
    {
        startPage();
        List<HmyPigPregnancy> list = pigPregnancyService.selectPigPregnancyList(
                pigCode,pregnancyTestType,
                pregnancyTestManager,
                dateStart,dateEnd);
        return getDataTable(list);
    }
    /**
     * @param hmyPigPregnancy
     * @return com.ruoyi.common.core.web.domain.AjaxResult
     * @author ZHL
     * @date 2024/1/29 19:10
     * @description  新增猪只分娩记录
     */
    @RequiresPermissions("hmy:pigPregnancy:add")
    @Log(title = "猪只分娩记录管理", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody HmyPigPregnancy hmyPigPregnancy)
    {
        return toAjax(pigPregnancyService.insertPigPregnancy(hmyPigPregnancy));
    }
    /**
     * 根据PregnancyId获取单个分娩记录信息
     *
     * @param PregnancyId
     * @return
     */
    @RequiresPermissions("hmy:pigPregnancy:query")
    @GetMapping("getInfo/{PregnancyId}")
    public AjaxResult selectPigPregnancyByPregnancyId(@PathVariable Long PregnancyId) {
        return AjaxResult.success(pigPregnancyService.selectPigPregnancyByPregnancyId(PregnancyId));
    }
    /**
     * 根据pigBreedId修改妊检记录信息
     *
     * @param
     * @return
     */
    @PostMapping("update")
    @Log(title = "妊检记录管理", businessType = BusinessType.UPDATE)
    @RequiresPermissions("hmy:pigPregnancy:update")
    public AjaxResult updatePigPregnancy(@RequestBody HmyPigPregnancy hmyPigPregnancy) {
        return toAjax(pigPregnancyService.updatePigPregnancy(hmyPigPregnancy));

    }

    /**
     * 根据PregnancyId删除妊检记录信息
     *
     * @param PregnancyIds
     * @return
     */
    @DeleteMapping("del/{PregnancyIds}")
    @RequiresPermissions("hmy:pigPregnancy:del")
    public AjaxResult delPigLiveByPigLiveId(@PathVariable Long[] PregnancyIds) {
        return toAjax(pigPregnancyService.deletePigPregnancyByPregnancyIds(PregnancyIds));
    }

    @GetMapping("findAllStaffName")
    public AjaxResult findAllStaffName(){
        return AjaxResult.success(pigPregnancyService.findAllStaffName());
    }
}
